package de.mhus.lib.core.service;

import de.mhus.lib.core.config.IConfig;
import de.mhus.lib.core.directory.DirectoryNode;
import de.mhus.lib.core.lang.BaseControl;
import de.mhus.lib.core.lang.MObject;

public class ConfigProvider extends MObject {

	public DirectoryNode getConfig(Object owner, DirectoryNode def) {
		IConfig config = null;
		if (owner instanceof MObject) {
			config = BaseControl.getBaseOf(((MObject)owner)).base(IConfig.class);
		} else {
			config = base(IConfig.class);
		}
		if (config != null) {
			String name = owner.getClass().getCanonicalName();
			DirectoryNode cClass = config.getNode(name);
			if (cClass != null) {
				log().t("found",name);
				return cClass;
			} else {
				log().t("not found",name);
			}
		}
		return def;
	}

}
